<?php
	//set POST variables
	$url = 'http://128.199.213.71:9292/';
	
	// if isBuy is true, buy 
	// else sell
	function commitTransaction($isBuy, $aRic, $aQuantity, $aBrokerId, $aType) {
		if($isBuy == TRUE) {
			$url = 'http://128.199.213.71:9292/'.'buy';
			echo $url;
			echo "<br />";
		} else {
			$url = 'http://128.199.213.71:9292/'.'sell';
			echo $url;
			echo "<br />";
		}
		/*
		$payLoad = array(
								"ric" => urlencode($aRic),
								"quantity" => urlencode($aQuantity),
								"brokerId" => urlencode($aBrokerId),
								"typ" => urlencode($aType)
						);
						

		$postString = "";
		//url-ify the data for the POST
		foreach($payLoad as $key=>$value) { 
			$postString .= $key.':'.$value.',';
		}
		rtrim($postString, ",");
		*/
		
		$postString = "{\"ric\" : \"$aRic\", \"quantity\" : $aQuantity, \"brokerId\" : \"$aBrokerId\", \"type\" : \"$aType\" }";
		
		var_dump($postString);

		//open connection
		$cURLHandle = curl_init();

		//set the url, number of POST vars, POST data
		curl_setopt($cURLHandle,CURLOPT_URL, $url);
		curl_setopt($cURLHandle,CURLOPT_POST, count(4));
		curl_setopt($cURLHandle,CURLOPT_POSTFIELDS, $postString);

		//execute post
		$result = curl_exec($cURLHandle);

		//close connection
		curl_close($cURLHandle);
	}
	
	echo 'hello world <br />';
	// invalid json
	commitTransaction(TRUE, "0005.HK", 5000, "CIS1234", "Market");
	
	// invalid json
	commitTransaction(FALSE, "0005.HK", 5000, "CIS1234", "Market");
	echo '<br />hello world till the end';
?>